package com.nq.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nq.common.ServerResponse;
import com.nq.dao.StAllocationSettingMapper;

import com.nq.pojo.StAllocationSetting;
import com.nq.pojo.vo.StAllocationSettingVo;
import com.nq.service.IStAllocationSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;


@Service
public class StAllocationSettingServiceImpl  extends ServiceImpl<StAllocationSettingMapper, StAllocationSetting> implements IStAllocationSettingService {


    @Resource
    private StAllocationSettingMapper stAllocationSettingMapper;

    @Override
    public List<StAllocationSettingVo> listSetting() {
        return stAllocationSettingMapper.listSetting();
    }

    @Override
    public ServerResponse updateOrAddSetting(Integer id, String low, String high, String rate, Integer level, Integer number, HttpServletRequest request) {
        StAllocationSetting setting = new StAllocationSetting();
        setting.setHigh(new BigDecimal(high));
        setting.setLow(new BigDecimal(low));
        setting.setLevel(level);
        setting.setNumber(number);
        setting.setRate(new BigDecimal(rate));
        if (null == id) {
            stAllocationSettingMapper.insert(setting);
        }
        else {
            setting.setId(id);
            stAllocationSettingMapper.updateById(setting);
        }

        return ServerResponse.createBySuccess("操作成功！");
    }

    @Override
    public ServerResponse delSetting(Integer id, HttpServletRequest request) {
        stAllocationSettingMapper.deleteById(id);
        return ServerResponse.createBySuccess("操作成功！");
    }

}
